<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>工程概况</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/layui/css/layui.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/admin.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/style.css"
      media="all"
    />
  </head>
  <body>
    <div class="layui-fluid">
      <img
        src="../../layuiadmin/images/backPage.png"
        class="backPreviousPage"
      />
      <button class="layui-btn layuiadmin-btn-useradmin downLoadWord">
        下载
      </button>
      <button class="layui-btn layuiadmin-btn-useradmin deleteTechnical">
        删除
      </button>
      <form
        class="layui-form returnInstructionsBox"
        action=""
        style="width: calc(100% - 100px)"
      >
        <div class="layui-form-item">
          <label class="layui-form-label">退回说明：</label>
          <div class="layui-input-block">
            <div class="returnInstructions"></div>
          </div>
        </div>
        <div class="layui-form-item">
          <div style="text-align: center">
            <button type="button" class="layui-btn" id="test10">
              技术草稿重新上传
            </button>
            <!-- <div class="layui-hide" id="uploadDemoView">
            <hr>
            <img src="" alt="上传成功后渲染" style="max-width: 196px">
          </div> -->
          </div>
        </div>
      </form>

      <!-- <div class="tuihui">
      <textarea class="layui-textarea">1111</textarea>

    </div> -->
      <div class="time_axis">
        <div class="time_box">
          <div class="time_box_list">
            <ul class="time_horizontal"></ul>
          </div>
        </div>
      </div>
      <iframe id="pdf" width="100%" height="800px"></iframe>
      <div class="seePdfBox"></div>
    </div>
    <script src="../../layuiadmin/modules/const_config.js"></script>
    <script src="../../layuiadmin/modules/jTools.js"></script>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script>
      layui
        .config({
          base: "../../layuiadmin/", //静态资源所在路径
        })
        .extend({
          index: "lib/index", //主入口模块
        })
        .use(["index", "contlist", "table", "upload"], function () {
          var table = layui.table,
            $ = layui.$,
            upload = layui.upload,
            form = layui.form,
            uuid = layui.data("uuid").key,
            reviewType = layui.data("reviewType").key,
            type = layui.data("technicalType").key,
            fileid = "";
          //拖拽上传
          upload.render({
            elem: "#test10",
            accept: "file",
            url: base_url + "/Technical/technicalfile",
            headers: {
              Accept: "application/json; charset=utf-8",
              Authorization: layui.sessionData("userToken").key,
            },
            before: function (obj) {
              this.data = {
                uuid: uuid,
                reviewType: reviewType,
              };
              layer.load(2, { time: 10 * 1000 });
            },
            done: function (res) {
              layer.closeAll();
              layer.msg(res.message);
            },
          });
          permissionList();
          function permissionList() {
            $.ajax({
              type: "post",
              async: true, //异步执行
              url: base_url + "/Technical/permissionList",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              data: JSON.stringify({
                uuid: uuid,
                type: 1,
                reviewType: reviewType,
              }),
              success: function (data) {
                var data = data.data.reverse();
                var html = "";
                for (var i = 0; i < data.length; i++) {
                  if (data[i].returnedState == 1) {
                    $(".time_axis").hide();
                    $(".deleteTechnical").hide();
                    $(".returnInstructionsBox").show();
                    $(".returnInstructions").text(data[i].returnOpinion);
                    $("#pdf").attr(
                      "src",
                      "../../layuiadmin/web/viewer.html?file=" +
                        data[i].pdfName +
                        ""
                    );
                    $(".downLoadWord").on("click", function () {
                      window.location.href = data[0].fileName;
                    });
                  } else {
                    if (i == data.length - 1) {
                      fileid = data[i].fileId;
                      html += `
                      <li class="time_horizontal_part" data-id="${data[i].pdfName}" data-fileid="${data[i].fileId}" data-name="${data[i].fileName}">
                          <b class="active"></b>
                          ${data[i].createTime}<br/>
                      </li>`;
                      $("#pdf").attr(
                        "src",
                        "../../layuiadmin/web/viewer.html?file=" +
                          data[i].pdfName +
                          ""
                      );
                    } else {
                      html += `
                      <li class="time_horizontal_part" data-id="${data[i].pdfName}" data-fileid="${data[i].fileId}" data-name="${data[i].fileName}">
                          <b></b>
                          ${data[i].createTime}<br/>
                      </li>`;
                    }
                    $(".time_horizontal").html(html);
                    $(".time_horizontal_part").on("click", function () {
                      var uuid = $(this).attr("data-id");
                      fileid = $(this).attr("data-fileid");
                      $(this).children("b").addClass("active");
                      $(this)
                        .siblings("li")
                        .children("b")
                        .removeClass("active");
                      $("#pdf").attr(
                        "src",
                        "../../layuiadmin/web/viewer.html?file=" + uuid
                      );
                    });
                    $(".downLoadWord").on("click", function () {
                      window.location.href = $(".active")
                        .parent()
                        .attr("data-name");
                    });
                  }
                }

                $(".time_horizontal").scrollLeft(
                  $(".time_horizontal")[0].scrollWidth
                );
                // $("#pdf").attr("src","../../layuiadmin/web/viewer.html?file="+data[0].pdfName+"");
              },
            });
          }
          $(".deleteTechnical").on("click", function () {
            $.ajax({
              type: "post",
              async: true, //异步执行
              url: base_url + "/Technical/technicaldelect",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              data: JSON.stringify({ fileid: fileid }),
              success: function (data) {
                if ((data.code = "200")) {
                  var dom = document.querySelectorAll("ul>li");
                  var url = $(".active").parent().attr("data-id");
                  if (dom.length == 1) {
                    $("#pdf").attr("src", " ");
                  } else {
                    permissionList();
                  }
                  layer.confirm("确认删除吗?", function (index) {
                    $(".active").parent().remove();
                    layer.msg(data.message, { icon: 6 });
                  });
                } else {
                  layer.msg(data.message, { icon: 5 });
                }
              },
            });
          });
          $(".backPreviousPage").on("click", function () {
            $(this).attr("lay-href", "./pages/technicalReview.html");
          });
        });
    </script>
  </body>
</html>
